package com.activitycode.view;



import java.util.ArrayList;
import java.util.List;

import com.activitycode.util.BaseTask;
import com.activitycode.util.ScreenManager;

import android.app.Activity;
import android.os.Bundle;


public class BaseActivity extends Activity{
	protected ScreenManager screenManager = ScreenManager.getScreenManager();
	protected List<BaseTask> taskList = new ArrayList<BaseTask>();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		screenManager.pushActivity(this);
	}
	
	@Override
	protected void onPause(){
		super.onPause();
	}
	
	@Override
	protected void onResume(){
		super.onResume();
	}
	
	@Override
	protected void onDestroy(){
		super.onDestroy();
		cancelTasks();
	}
	
	protected void addTask(BaseTask task){
		try {
			taskList.add(task);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}		
	}
	
	protected void cancelTasks(){
		for(int i=0;i<taskList.size();i++){
		try {			
			BaseTask task = taskList.get(i);
			if(task!=null&&!task.isCancelled()){
				task.cancelTasks();
			}			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		}
	}
	
}